if not Scene then
	Scene = {}
end

function getSceneData(cid, did, sid)
	if not cid or not did or not sid then
		return
	end

	local country = world[cid]
	if not country then
		return
	end

	local district = country[did]
	if not district then
		return
	end
	return district[sid]
end

function Scene.onCheckDistrict(cid, did, lvl)
	print("try to enter disctrict:", cid, did)
	local country = world[cid]
	if not country then
		return false
	end

	local district = country[did]
	if not district then
		return false
	end

	--
	--	add some logic of check level
	--
	return true
end

function Scene.onCreate(cid, did, sid, scnmgr, progress)
	if not scnmgr then
		log.error("failed to create scene, null scene manager")
		return 0
	end
	if not progress then
		log.error("failed to create scene, null progress")
		return 0
	end

	local sd = getSceneData(cid, did, sid)
	if not sd then
		log.error("failed to create scene, null static scene data")
		return 0
	end

	--
	--	add some dependency checking here, such as:
	--	level requirement
	--	scene dependency
	--	progress data
	--

	local scene = scnmgr:addScene(cid, did, sid, sd.type)
	if not scene then
		log.error("failed to create scene, manager error")
	end
end

function Scene.onLoad(scene)
	log.info("loading scene ...")
end

function Scene.onLoadCity(scene)
	log.info("loading scene for city ...")
	local cid, did, sid = scene:getStaticID()
	local sd = getSceneData(cid, did, sid)
	if not sd then
		log.error("failed to load combat scene")
		return
	end
	
	local m = scene:addN(10001)
	if m then
		m:setPosition(1, 1, 0)
	end

	m = scene:addN(10002)
	if m then
		m:setPosition(1, 2, 0)
	end
	
	m = scene:addN(10003)
	if m then
		m:setPosition(3, 2, 0)
	end

end

function Scene.onLoadCombat(scene)
	log.info("loading scene for combat ...")
	local cid, did, sid = scene:getStaticID()
	local sd = getSceneData(cid, did, sid)
	if not sd then
		log.error("failed to load combat scene")
		return
	end
	
end

function Scene.onStartCombat(scene, datamgr, wid)
	log.info("scene start combatting: ", wid)
	local cid, did, sid = scene:getStaticID()
	local prev_wid = datamgr:get(cid, did, sid)
	if prev_wid+1<wid then
		log.error("failed to start combat, required wave not complete")
		return false
	end
	local sd = getSceneData(cid, did, sid)
	if not sd then
		log.error("failed to start combat, invalid static data")
		return false
	end

	local wave = sd[wid]
	if not wave then
		log.error("failed to start combat, invalid wave id")
		return false
	end

	local wd = monstergroups[wave]
	if not wd then
		log.error("failed to start combat, invalid wave data, no form found")
		return false
	end

	for fpos, mid in ipairs(wd) do
		if mid>0 then
			local m = scene:addM(mid)
			if m then
				m:setPosition(1, 1, fpos)
			end
		end
	end
end

function Scene.onEndCombat(scene)
	log.info("scene end combatting: ")
end
